package com.principle.segregation;

public class InfSegregation2 {

    public static void main(String[] args) {
        A1 a1 = new A1();
        a1.depend1(new B1());
        a1.depend2(new B1());
        a1.depend3(new B1());

        C1 c1 = new C1();
        c1.depend1(new D1());
        c1.depend4(new D1());
        c1.depend5(new D1());
    }

}

/**
 * 有一个接口 ，里面5个方法 operation1,operation2,operation3,operation4,operation5
 * B D 实现这个两个接口
 * A通过接口依赖了B，调用了B中的operation1,operation2,operation3
 * C通过接口依赖了D，调用了D中的operation1,operation4,operation5
 * <p>
 * 问题：
 * A只调用了  1,2，3方法，但是B却要实现接口的所有方法
 * 同样 C只调用了 1 ，4,5 方法 ，但是D却要实现接口的所有方法
 *
 * 解决方法，让MyInterface派生出两个新的接口,MyInterface2 , MyInterface3
 * 让B实现MyInterface2
 * 让D实现MyInterface3
 */

interface MyInterface1 {
    void operation1();
}

interface MyInterface2 extends MyInterface1 {
    void operation2();
    void operation3();
}

interface MyInterface3 extends MyInterface1 {
    void operation4();
    void operation5();
}

class B1 implements MyInterface2{

    @Override
    public void operation1() {
        System.out.println("B1 实现了 operation1");
    }

    @Override
    public void operation2() {
        System.out.println("B1 实现了 operation2");
    }

    @Override
    public void operation3() {
        System.out.println("B1 实现了 operation3");
    }
}


class D1 implements MyInterface3{

    @Override
    public void operation1() {
        System.out.println("D1 实现了 operation1");
    }

    @Override
    public void operation4() {
        System.out.println("D1 实现了 operation4");
    }

    @Override
    public void operation5() {
        System.out.println("D1 实现了 operation5");
    }
}

class A1{
    public void depend1(MyInterface2 i){
        i.operation1();
    }
    public void depend2(MyInterface2 i){
        i.operation2();
    }
    public void depend3(MyInterface2 i){
        i.operation3();
    }
}

class C1{
    public void depend1(MyInterface3 i){
        i.operation1();
    }
    public void depend4(MyInterface3 i){
        i.operation4();
    }
    public void depend5(MyInterface3 i){
        i.operation5();
    }
}





